package leetcode.editor.cn.q1_300.q100;

/**
 * @author qidi
 * @date 2022-01-10 16:37:46
 */
class Q0125_ValidPalindrome {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public boolean isPalindrome(String s) {
            char[] chars = s.toCharArray();
            int l = 0;
            int r = chars.length - 1;
            while (l <= r) {
                if (!(chars[l] >= 'A' && chars[l] <= 'Z' || chars[l] >= 'a' && chars[l] <= 'z' || chars[l] >= '0' && chars[l] <= '9')) {
                    l++;
                    continue;
                }
                if (!(chars[r] >= 'A' && chars[r] <= 'Z' || chars[r] >= 'a' && chars[r] <= 'z' || chars[r] >= '0' && chars[r] <= '9')) {
                    r--;
                    continue;
                }
                int ll = chars[l] <= 'Z' ? chars[l] + 32 : chars[l];
                int rr = chars[r] <= 'Z' ? chars[r] + 32 : chars[r];
                if (ll != rr) {
                    return false;
                } else {
                    l++;
                    r--;
                }
            }
            return true;
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0125_ValidPalindrome().new Solution();
        System.out.println((int) '0');
        System.out.println(solution.isPalindrome("0P"));
        System.out.println(solution.isPalindrome("A man, a plan, a canal: Panama"));
        System.out.println(solution.isPalindrome("race a car"));
    }
}